mspgcc_version := 20120406

normal_patchs_tarball := mspgcc-$(mspgcc_version).tar.bz2
normal_patchs_origin_dir := mspgcc-$(mspgcc_version)
normal_patchs_remote := http://sourceforge.net/projects/mspgcc/files/mspgcc/$(normal_patchs_tarball)

lts_files := msp430-gcc-4.6.3-20120406-sf3540953.patch msp430-gcc-4.6.3-20120406-sf3559978.patch
lts_local_files := $(foreach file, $(lts_files), lts_patchs/$(file))
lts_repo := http://sourceforge.net/projects/mspgcc/files/Patches/LTS/20120406

need_patch_components := binutils gcc gdb
need_patch_components_src := $(foreach compo, $(need_patch_components), ../$(compo)/sources)

all:
# NOTHING

.PHONY:init
init: sources
sources: normal_patchs lts_patchs

normal_patchs: $(normal_patchs_tarball)
	@echo extracting files...
	@tar xmf $(normal_patchs_tarball) && \
	mv $(normal_patchs_origin_dir) normal_patchs
	@echo extract files done

$(normal_patchs_tarball):
	@wget -c -O $(normal_patchs_tarball) $(normal_patchs_remote);

lts_patchs: $(lts_local_files)

%.patch:
	@if [ ! -d lts_patchs ]; then mkdir lts_patchs; fi
	@wget -c -O$@ $(lts_repo)/$(notdir $@)

# NOT NEEDED
patch: .patched_sources

.patched_sources: $(need_patch_components_src) normal_patchs lts_patchs
	@./patchmanage.sh patch && \
	touch .patched_sources

unpatch:
	@if [ -f .patched_sources ]; then ./patchmanage.sh unpatch ; rm .patched_sources; fi;

clean:
# NOTHING

distclean: clean
	@$(RM) -r .patched_sources normal_patchs

distdistclean: distclean
	@$(RM) -r $(normal_patchs_tarball) lts_patchs

install:
# NOTHING

uninstall:
# NOTHING
